package com.ruoyi.web;

/**
 * @author linxz
 * @since 2025-01-18 02:16
 */

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

public class TestMain {

    public static void main(String[] args) {
        String server = "27.30.77.24"; // FTP服务器地址
        int port = 22; // FTP端口，默认为21
        String user = "root"; // FTP用户名
        String pass = "Aa786324872!"; // FTP密码
        String remoteDir = "/home/files/engineai/config"; // 远程服务器目标文件夹路径
        File localFile = new File("/Users/linxz/Downloads/1.mp4"); // 要上传的本地文件路径

//        try {
//            uploadFileToRemote(server, port, user, pass, remoteDir, localFile);
//            System.out.println("Upload successful!");
//        } catch (IOException e) {
//            e.printStackTrace();
//        }

    }

//    private static void uploadFileToRemote(String server, int port, String user, String pass,
//                                           String remoteDir, File localFile) throws IOException {
//        FTPClient ftpClient = new FTPClient();
//        try {
//            ftpClient.connect(server, port);
//            ftpClient.login(user, pass);
//
//            // 设置文件类型为二进制（非常重要）
//            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
//
//            // 更改工作目录到目标文件夹
//            ftpClient.changeWorkingDirectory(remoteDir);
//
//            // 创建输入流以读取本地文件
//            try (FileInputStream inputStream = new FileInputStream(localFile)) {
//                // 上传文件
//                boolean done = ftpClient.storeFile(localFile.getName(), inputStream);
//                if (done) {
//                    System.out.println("The file was uploaded successfully.");
//                } else {
//                    System.out.println("Failed to upload the file.");
//                }
//            }
//
//            // 完成后退出
//            ftpClient.logout();
//
//        } catch (IOException ex) {
//            ex.printStackTrace();
//        } finally {
//            try {
//                if (ftpClient.isConnected()) {
//                    ftpClient.disconnect();
//                }
//            } catch (IOException ex) {
//                ex.printStackTrace();
//            }
//        }
//    }
}
